﻿using System;

class ExchangeBits

        // Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.

{
    static void Main()
    {
        Console.Write("Please enter positive integer: ");
        int number = int.Parse(Console.ReadLine());
        int mask1 = 7 << 3;
        int mask2 = 7 << 24;
        int mask1andNumber = number & mask1;
        int mask2andNumber = number & mask2;
        int exchange1 = mask1andNumber << 20;
        int exchange2 = mask2andNumber >> 20;
        int semi = number | exchange1;
        int result = semi | exchange2;
        Console.WriteLine("was {0} = {1}", number, Convert.ToString(number, 2).PadLeft(32, '0'));
        Console.WriteLine("The new number is: {0} = {1}", result, Convert.ToString(result, 2).PadLeft(32, '0'));
    }
}

